const MixinYY = {
    data() {
        return {
               fileNames:''

        }
    },
    methods: {
        openEdit(val) {
            this.listNew = val
            this.showMore = true
        },
        onSelect(val) {
            this.showMore = false
            switch (val.id) {
                case 1:
                    this.joinBtn(this.listNew, "邮箱")
                    break;
                case 2:
                    this.fileNamePop = 1
                    this.joinBtn(this.listNew, "同步")
                    break;
                case 3:
                    this.fileNamePop = 2
                    this.joinBtn(this.listNew, "分享")
                    break;
                case 4:
                    // 重命名
                    this.showPopName = true
                    this.inputText = this.listNew.messageTitle
                    break;
                case 5:
                    this.deleteList()
                    break;
                case 6:
                    this.getInfo()
                    // 预览
                    break;
                default:
            }

        },
        // 删除功能相关代码
        deleteList() {
            var btnArray = ["取消", "删除"];
            var i = 0
            mui.confirm(
                "删除后音频文件及转写结果不可恢复",
                "删除文件",
                btnArray,
                (e) => {
                    if (i > 0) return
                    i++
                    if (e.index == 1) {
                        this.delAdd(0, this.listNew.id)
                    } else {}
                }
            );

        },
        // 分享功能相关代码
        joinBtn(item, text) {
            this.fileNames = item.messageTitle
            console.log(this.fileNames,64)
            this.radio = "1"
            if (item.translation == 0 || item.translation == 2 || item.translation == 5) {
                mui.toast("音频文件正在转写，请稍后" + text, {
                    duration: "long",
                    type: "div",
                });
                return
            } else if (text == "邮箱") {
                this.emailBtn = "1"
                this.showEmailPop = true
            } else {
                this.radio = '1'
                this.showShare = true
            }

        },
        shuaxin() {
            // $("#circle_img").css("animation", "circle 1s linear infinite")
            // setTimeout(() => {
            this.num = 0
            this.loading = false
            this.finished = false
            this.listData = []
            this.getShorthandList(0);
            // }, 1000)
        },
        reName() {
            console.log(this.inputText, "标题")
            userId = sessionStorage.getItem("userId");
            iscp_port = sessionStorage.getItem("iscp_port") || "";
            let data = {
                "id": this.listNew.id,
                "userId": userId,
                "messageTitle": this.inputText,
                "timestamp": new Date().getTime() + ""
            };
            data = JSON.stringify(data)
            let sign = sm3(data);
            let AuthenticationSession = sessionStorage.getItem("Authentication");
            $.ajax({
                url: localUrlLink + iscp_port + "/tjAiAssistant/voice/renameMeetingTitle",
                type: "post",
                async: false,
                dataType: "json",
                data: data,
                headers: {
                    "Content-Type": "application/json;charset=UTF-8",
                    Authentication: AuthenticationSession,
                    sign: sign
                },
                success: (res, txt, xhr) => {
                    if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
                        let Authentication = xhr.getResponseHeader("Authentication")
                        if (res.code == 200) {
                            if (Authentication) {
                                sessionStorage.setItem("Authentication", Authentication);
                                mui.toast('修改成功', {
                                    duration: 1000,
                                    type: 'div'
                                })
                                this.showPopName = false
                                this.shuaxin()
                            }
                        } else {
                            mui.toast("修改失败", {
                                duration: 'long',
                                type: 'div'
                            })
                        }
                    } else {
                        mui.toast('完整性校验失败', {
                            duration: 'long',
                            type: 'div'
                        })
                    }
                },
                error: (e) => {
                    // $(".curtainVoice").css("display", "none");
                    mui.toast('请求异常,请稍后再试', {
                        duration: 'long',
                        type: 'div'
                    })
                },
            });
        },
        onOpen() {
            this.isSearchFocused = false,
                this.shuaxin()

        },
        deleteAllFiles() {
            var btnArray = ["取消", "确定"];
            var i = 0
            mui.confirm(
                "确认清空列表",
                "清空",
                btnArray,
                (e) => {
                    if (i > 0) return
                    i++
                    if (e.index == 1) {
                        this.delAll()
                    }
                }
            );
        },

        // 语音列表一键删除功能
        delAll() {
            userId = sessionStorage.getItem("userId");
            iscp_port = sessionStorage.getItem("iscp_port") || "";
            let data = {
                "userId": userId,
                "timestamp": new Date().getTime() + ""
            };
            data = JSON.stringify(data)
            let sign = sm3(data);
            let AuthenticationSession = sessionStorage.getItem("Authentication");
            $.ajax({
                url: localUrlLink + iscp_port + "/tjAiAssistant/voice/clearVoiceAll",
                type: "post",
                async: false,
                dataType: "json",
                data: data,
                headers: {
                    "Content-Type": "application/json;charset=UTF-8",
                    Authentication: AuthenticationSession,
                    sign: sign
                },
                success: (res, txt, xhr) => {
                    if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
                        let Authentication = xhr.getResponseHeader("Authentication")
                        if (res.code == 200) {
                            if (Authentication) {
                                sessionStorage.setItem("Authentication", Authentication);
                                mui.toast('清空列表成功', {
                                    duration: 1000,
                                    type: 'div'
                                })
                                this.shuaxin()
                            }
                        } else {
                            mui.toast(res.resultValue, {
                                duration: 'long',
                                type: 'div'
                            })
                        }
                    } else {
                        mui.toast('完整性校验失败', {
                            duration: 'long',
                            type: 'div'
                        })
                    }
                },
                error: (e) => {
                    // $(".curtainVoice").css("display", "none");
                    mui.toast('请求异常,请稍后再试', {
                        duration: 'long',
                        type: 'div'
                    })
                },
            });
        },
        // 录音文件同步内网邮箱
        sendVoice() {
            iscp_port = sessionStorage.getItem("iscp_port") || "";
            let data = {
                "id": this.listNew.attachmentId,
                "messageTitle": this.listNew.messageTitle,
                "userId": sessionStorage.getItem("userId"),
                "saveType": 3,
                "sceneNo":35,
                "unitId": sessionStorage.getItem("unitId"),
                "timestamp": new Date().getTime() + ""
            };
            data = JSON.stringify(data)
            let sign = sm3(data);
            let AuthenticationSession = sessionStorage.getItem("Authentication");
            $.ajax({
                url: localUrlLink + iscp_port + "/tjAiAssistant/Recording/recordSendMail",
                type: "post",
                async: false,
                dataType: "json",
                data: data,
                headers: {
                    "Content-Type": "application/json;charset=UTF-8",
                    Authentication: AuthenticationSession,
                    sign: sign
                },
                success: (res, txt, xhr) => {
                    if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
                        let Authentication = xhr.getResponseHeader("Authentication")
                        if (res.code == 200) {
                            if (Authentication) {
                                sessionStorage.setItem("Authentication", Authentication);
                                // if (this.action == 3) {
                                    showConfirmDialog("同步完成，请及时到内网网站aioa.sgcc.com.cn下载使用"," ")
                                    this.showShare = false
                            }
                        } else if (res.code == 500) {
                            if (this.action == 3) {
                                syncToast('同步失败', 1500, "error", true)
                            } else {
                                mui.toast(res.resultValue, {
                                    duration: 'long',
                                    type: 'div'
                                })
                            }

                        } else {
                            mui.toast('请求异常,请稍后再试', {
                                duration: 'long',
                                type: 'div'
                            })
                        }
                    } else {
                        mui.toast('完整性校验失败', {
                            duration: 'long',
                            type: 'div'
                        })
                    }
                },
                error: (e) => {
                    // $(".curtainVoice").css("display", "none");
                    mui.toast('请求异常,请稍后再试', {
                        duration: 'long',
                        type: 'div'
                    })
                },
            });
        },

        downFile() {
            let that_ = this
            // 同步到内网
            if (that_.fileNamePop == 1) {

                if (that_.radio == "1") { // 录音文件发送与同步
                    that_.sendVoice()
                    return
                } else if (that_.radio == "2") { //会议录音发送与同步
                    that_.sendMail(3)
                    return
                } else { //会议纪要发送与同步
                    that_.sendMailJy(3)
                    return
                }
            }
            // 分享会议记录
            if (that_.radio == "2") {
                that_.checkJion()
                return
            }
            // 分享纪要
            if (that_.radio == "3") {
                that_.jyInjoin()
                return
            }
            // 分享录音文件
            $("#curtain").css("display", "block");
            const timestamp = new Date().getTime() + ""
            that_.showShare = false

            let userId = sessionStorage.getItem("userId");
            // let recordArr = JSON.parse(res.result)
            that_.channelId = "net_upload_" + that_.createNonceStr(16) + new Date()
                .getTime() + "";
            wx.invoke("multiWindows_subscribe", {
                channelId: that_.channelId
            }, function (res) {
                console.log(res.data.result, "监听的数据")
                if (res.data.event == "success") {
                    $("#curtain").css("display", "none");
                    wx.invoke("ext_Intent_SystemShare", {
                        data: {
                            content: decodeURIComponent(res.data.result.replace("file://", "")),
                            contentType: "FilePath",
                            fileName: unescape(escape(that_.fileNames)),
                        }
                    }, function (res) {
                        wx.invoke("getZipAppDirectory", {
                            "type": "STORAGE_ROOT_DIR", //APP_ROOT_DIR
                        }, function (res) {
                            console.log(that_.fileNames, 346)
                            that_.paths = res.directory
                            console.log(that_.paths, "that_.paths")
                            if (that_.isflageIOX) {
                                wx.invoke("ext_FileManager_Remove", {
                                        "data": {
                                            fileList: [res.directory +
                                                unescape(escape(that_.fileNames)),
                                            ]

                                        }
                                    },
                                    function (res) {
                                        console.log(
                                            "ext_FileManager_Remove",
                                            res);
                                    })
                            }

                        })
                    })
                }
            })

            //获取绝对路径
            var path
            wx.invoke("getZipAppDirectory", {
                "type": "STORAGE_ROOT_DIR", //STORAGE_ROOT_DIR
            }, function (res) {
                console.log(unescape(escape(that_.fileNames)),375)
                var path = res.directory ? res.directory : ''
                // 2.开始下载任务
                let voiceSign = sm3(timestamp + "&" + that_.listNew.id);
                var URL = localUrlLink + iscp_port +
                    `/tjAiAssistant/voice/downloadAudioFileById?Authentication=${sessionStorage.getItem("Authentication")}&id=${that_.listNew.id}&sign=${voiceSign}&timestamp=${timestamp}`
                wx.invoke("ext_Net_Download", {
                    data: {
                        cmd: "download",
                        url: URL, //下载url地址
                        header: {},
                        id: that_.channelId, //与channelId保持一致
                        timeout: 10,
                        fileName: unescape(escape(that_.fileNames)), //保存的文件名
                        path: path //文件保存路径使用getZipAppDirectory获取
                    }

                }, function (res) {
                    console.log("downloadfile ", res);
                    if (res.event === 'start') { //任务开始成
                        console.log("任务id：", res.id)
                    }
                    if (res.event === 'fail') { //任务失败
                    }
                })
            })
        },
        jyInjoin() {
            let this_ = this
            var fileNames = this_fileNames + docx
            const timestamp = new Date().getTime() + ""
            this_.channelId = "net_upload_" + createNonceStr(16) + new Date()
                .getTime() + "";
            wx.invoke("multiWindows_subscribe", {
                channelId: this_.channelId
            }, function (res) {
                console.log(res.data.result, "监听的数据")
                if (res.data.event == "success") {
                    $("#curtain").css("display", "none");
                    wx.invoke("ext_Intent_SystemShare", {
                        data: {
                            content: decodeURIComponent(res.data.result.replace("file://", "")),
                            contentType: "FilePath",
                            fileName: unescape(escape(fileNames)),
                        }
                    }, function (res) {
                        if (isflageIOX) {
                            wx.invoke("getZipAppDirectory", {
                                "type": "STORAGE_ROOT_DIR", //APP_ROOT_DIR
                            }, function (res) {
                                console.log(res, 999)
                                wx.invoke("ext_FileManager_Remove", {
                                        "data": {
                                            fileList: [res.directory +
                                                unescape(escape(fileNames)),
                                            ]
                                        }
                                    },
                                    function (res) {
                                        console.log("ext_FileManager_Remove",
                                            res);
                                    })
                            })
                        }
                    })
                }
            })
            //获取绝对路径
            var path
            wx.invoke("getZipAppDirectory", {
                "type": "STORAGE_ROOT_DIR", //STORAGE_ROOT_DIR
            }, function (res) {
                console.log(res, "路径")
                var path = res.directory ? res.directory : ''
                // 2.开始下载任务
                let voiceSign = sm3(timestamp + "&" + this_.listNew.minutesAttachmentId);
                var URL = localUrlLink + iscp_port +
                    `/tjAiAssistant/shareFile/downloadToWord?Authentication=${sessionStorage.getItem("Authentication")}&id=${this_.listNew.minutesAttachmentId}&sign=${voiceSign}&timestamp=${timestamp}`
                wx.invoke("ext_Net_Download", {
                    data: {
                        cmd: "download",
                        url: URL, //下载url地址
                        header: {},
                        id: this_.channelId, //与channelId保持一致
                        timeout: 10,
                        fileName: unescape(escape(fileNames)), //保存的文件名
                        path: path //文件保存路径使用getZipAppDirectory获取
                    }

                }, function (res) {
                    console.log("downloadfile ", res);
                    if (res.event === 'start') { //任务开始成
                        console.log("任务id：", res.id)
                    }
                    if (res.event === 'fail') { //任务失败
                    }
                })
            })
        },
        sendMailBtn() {
            if (this.emailBtn == "1") {
                this.sendMail(0)
            } else {
                this.sendMailJy(0)
            }
        },
        sendMailJy(saveType) {
            const userId = sessionStorage.getItem("userId");
            const orgId = sessionStorage.getItem("unitId")
            const timestamp = new Date().getTime() + ""
            if (sessionStorage.getItem("iscp_port")) {
                iscp_port = sessionStorage.getItem("iscp_port");
            } else {
                iscp_port = ""
            }
            let data = {
                "sceneNo": 62,
                "minutesAttachmentId": this.listNew.minutesAttachmentId,
                "orgId": orgId, //单位id
                "saveType": saveType, //单位id 3//同步 0 发邮箱
                "userId": userId, //用户id
                "timestamp": timestamp,
            };
            let AuthenticationSession = sessionStorage.getItem("Authentication");
            data = JSON.stringify(data)
            let sign = sm3(data);
            $.ajax({
                url: localUrlLink + iscp_port +
                    "/tjAiAssistant/IdentificationFile/minutesSendMail",
                type: "post",
                // async: false, //是否同步，false表示同步请求
                dataType: "json",
                data: data,
                headers: {
                    "Content-Type": "application/json;charset=UTF-8",
                    Authentication: AuthenticationSession,
                    sign: sign
                },
                success: (res, txt, xhr) => {
                    $(".curtain").css("display", "none");
                    if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
                        let Authentication = xhr.getResponseHeader("Authentication")
                        if (res.code == 200) {
                            if (Authentication) {
                                sessionStorage.setItem("Authentication", Authentication);
                                if (saveType == 3) {
                                    this.showShare = false
                                    showConfirmDialog("同步完成，请及时到内网网站aioa.sgcc.com.cn下载使用"," ")

                                } else {
                                    this.showEmailPop = false
                                    mui.toast("已发送邮箱", {
                                        duration: 1000,
                                        type: 'div'
                                    })
                                }
                            }

                        } else {
                            if (saveType == 3) {
                                syncToast('同步失败', 1500, "error", true)
                            } else {
                                mui.toast(res.resultValue, {
                                    duration: 'long',
                                    type: 'div'
                                })
                            }

                        }
                    } else {
                        mui.toast('完整性校验失败', {
                            duration: 'long',
                            type: 'div'
                        })
                    }

                },
                error: (e) => {
                    $(".curtain").css("display", "none");
                    mui.toast('请求异常,请稍后再试', {
                        duration: 1000,
                        type: 'div'
                    })
                },
            });
        },
        sendMail(saveType) {
            const userId = sessionStorage.getItem("userId");
            const orgId = sessionStorage.getItem("unitId")
            const timestamp = new Date().getTime() + ""
            if (sessionStorage.getItem("iscp_port")) {
                iscp_port = sessionStorage.getItem("iscp_port");
            } else {
                iscp_port = ""
            }
            var content = ''
            if(this.listNew.sectionMessage) {
                JSON.parse(this.listNew.sectionMessage).forEach((item, index) => {
                    if (index == 0) {
                        item.speakerName += "\n"
                    } else {
                        item.speakerName = "\n" + item.speakerName + "\n"
                    }
                    item.content.forEach((i) => {
                        if (i.subIndex == -1) {
                            i.word = "\n" + i.word
                        }
                        item.speakerName += i.word
                    })
                    content += item.speakerName
                })
            } else {
                content = this.listNew.message
            }
            let data = {
                "sceneNo": this.listNew.sectionMessage ? 33 : 31, //31:实时转写 32:语音笔记 33导入音频
                "messageTitle": this.listNew.messageTitle, //笔记标题
                "message": content,//笔记内容
                "orgId": orgId, //单位id
                "fileName": this.listNew.messageTitle,
                "saveType": saveType, //单位id
                "userId": userId, //用户id
                "timestamp": timestamp,
            };
            let AuthenticationSession = sessionStorage.getItem("Authentication");
            data = JSON.stringify(data)
            let sign = sm3(data);
            $.ajax({
                url: localUrlLink + iscp_port +
                    "/tjAiAssistant/IdentificationFile/voiceSendMail",
                type: "post",
                // async: false, //是否同步，false表示同步请求
                dataType: "json",
                data: data,
                headers: {
                    "Content-Type": "application/json;charset=UTF-8",
                    Authentication: AuthenticationSession,
                    sign: sign
                },
                success: (res, txt, xhr) => {
                    $(".curtain").css("display", "none");
                    if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
                        let Authentication = xhr.getResponseHeader("Authentication")
                        if (res.code == 200) {
                            if (Authentication) {
                                sessionStorage.setItem("Authentication", Authentication);
                                if (saveType == 3) {
                                    this.showShare = false
                                    showConfirmDialog("同步完成，请及时到内网网站aioa.sgcc.com.cn下载使用"," ")

                                } else {
                                    this.showEmailPop = false
                                    mui.toast("已发送邮箱", {
                                        duration: 1000,
                                        type: 'div'
                                    })
                                }
                            }

                        } else {
                            if (saveType == 3) {
                                syncToast('同步失败', 1500, "error", true)
                            } else {
                                mui.toast(res.resultValue, {
                                    duration: 'long',
                                    type: 'div'
                                })
                            }

                        }
                    } else {
                        mui.toast('完整性校验失败', {
                            duration: 'long',
                            type: 'div'
                        })
                    }

                },
                error: (e) => {
                    $(".curtain").css("display", "none");
                    mui.toast('请求异常,请稍后再试', {
                        duration: 1000,
                        type: 'div'
                    })
                },
            });
        },

        checkJion() {
            data = {
                sceneNo: this.listNew.sectionMessage ? 33 : 31,
                text: this.listNew.sectionMessage ? this.listNew.sectionMessage : this.listNew.message,
                title: this.listNew.messageTitle
            }
            greneralRequest("/tjAiAssistant/shareFile/shareToBase64", JSON.stringify(data),"",this.listNew.messageTitle)
        },
        getInfo() {
            if (sessionStorage.getItem("iscp_port")) {
                iscp_port = sessionStorage.getItem("iscp_port");
            } else {
                iscp_port = ""
            }
            let data = {
                "cId": this.listNew.minutesAttachmentId,
                "timestamp": new Date().getTime() + "",
            };
            data = JSON.stringify(data)
            let sign = sm3(data);
            let AuthenticationSession = sessionStorage.getItem("Authentication");
            $.ajax({
                url: localUrlLink + iscp_port + "/tjAiAssistant/voice/queryOperatingManualInfo",
                type: "POST",
                async: false, //是否同步，false表示同步请求
                dataType: "json",
                data: data,
                headers: {
                    "Content-Type": "application/json;charset=UTF-8",
                    Authentication: AuthenticationSession,
                    sign: sign
                },
                success: (res, txt, xhr) => {
                    if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
                        let Authentication = xhr.getResponseHeader("Authentication")
                        sessionStorage.setItem("Authentication", Authentication);
                        if (res.code == 200) {
                            var file = {
                                name: res.resultValue.name,
                                id: res.resultValue.id,
                                size: res.resultValue.size,
                            }
                            this.myPreviewFile(file)
                        } else {
                            mui.toast(res.resultValue, {
                                duration: 'long',
                                type: 'div'
                            })
                        }
                    } else {
                        mui.toast('完整性校验失败', {
                            duration: 'long',
                            type: 'div'
                        })
                    }
                },
                error: (e) => {
                    mui.toast('请求异常,请稍后再试', {
                        duration: 'long',
                        type: 'div'
                    })
                },
            });
        },
        /**
         * 预览文件的方法
         * 该方法会根据传入的文件信息生成下载链接，并调用微信的 `previewFile` 接口进行文件预览
         * @param {Object} file - 文件信息对象，包含文件的 id、name、size 等属性
         * @param {string} file.id - 文件的唯一标识
         * @param {string} [file.name] - 文件的名称
         * @param {number} [file.size] - 文件的大小
         */
        myPreviewFile(file) {
            console.log(88, file)
            let downUrl = localUrlLink + iscp_port + '/tjAiAssistant/common/download';
            downUrl += '?id=' + file.id;
            let Authentication = sessionStorage.getItem("Authentication");
            let timestamp = new Date().getTime() + "";
            let sign = sm3(timestamp + '&' + file.id)
            downUrl += '&Authentication=' + Authentication + '&timestamp=' + timestamp + '&sign=' + sign;
            console.log(778)
            wx.invoke('previewFile', {
                url: downUrl,
                isLocalUrl: 0,
                name: file.name || file.fileName,
                size: file.size || file.fileSize,
                hidePreviewMenuList: []
            });
        },

    },
};